package MultiNetworkingBase;

import java.util.ArrayList;

public class GameScreen {
	
	
	public static void switchToNameMenu(GraphicsManager gManager, UnitManager uManager, InputHandler iHandler, WarTug game){
		// This is the info for the name entry screen
		// Flush out the old screen components from GraphicsManager and InputHandler
		final GraphicsManager gMan = gManager;
		final UnitManager uMan = uManager;
		final InputHandler iHan = iHandler;
		final WarTug g = game;
		gManager.clearDrawableEntities();
		iHandler.clearButtonList();
		uManager.resetUnitLists();
		
		// Create the list of buttons that exist in the main menu screen
		ArrayList<Button> newButtons = new ArrayList<Button>();
		//Add the buttons here
		newButtons.add(new Button(10, 10, 50, 50, "Enter Your Name")); // Button displaying "Enter Your Name" duh.
		
		
		newButtons.add(new Button(10, 70, 50, 50, TextureHolder.tex/*mainMenuJoinButton*/)); // Join New Game Button		
		
		ArrayList<DrawableImage> newImages = new ArrayList<DrawableImage>();
		//Add the images here
		//newImages.add(new DrawableImage(0,0,25,10,10, TextureHolder.tex/*mainMenuBackground*/));
		
		//Update the graphics manager, screen index, and input handler
		giveDrawablesToGraphicsHandler(newButtons, newImages, gManager);
		iHandler.setButtonList(newButtons);
		game.currentScreen = Screen.mainMenu;
	}
	
	
	
	
	public static void switchToMainMenu(GraphicsManager gManager, UnitManager uManager, InputHandler iHandler, WarTug game){
		// Flush out the old screen components from GraphicsManager and InputHandler
		// Matt Cotter--THIS IS WEIRD!!
		final GraphicsManager gMan = gManager;
		final UnitManager uMan = uManager;
		final InputHandler iHan = iHandler;
		final WarTug g = game;
		gManager.clearDrawableEntities();
		iHandler.clearButtonList();
		uManager.resetUnitLists();
		
		// Create the list of buttons that exist in the main menu screen
		ArrayList<Button> newButtons = new ArrayList<Button>();
		//Add the buttons here
		newButtons.add(new Button(10, 10, 50, 50, TextureHolder.tex/*mainMenuHostButton*/, 
				new ButtonAction() {
					public void onClick() {
						GameScreen.switchToJoinMenu(gMan, uMan, iHan, g);
					}

					public void hover() {}})); // Host New Game Button
		
		newButtons.add(new Button(10, 70, 50, 50, TextureHolder.tex/*mainMenuJoinButton*/)); // Join New Game Button		
		
		ArrayList<DrawableImage> newImages = new ArrayList<DrawableImage>();
		//Add the images here
		//newImages.add(new DrawableImage(0,0,25,10,10, TextureHolder.tex/*mainMenuBackground*/));
		
		//Update the graphics manager, screen index, and input handler
		giveDrawablesToGraphicsHandler(newButtons, newImages, gManager);
		iHandler.setButtonList(newButtons);
		game.currentScreen = Screen.mainMenu;
	}
	
	public static void switchToJoinMenu(GraphicsManager gManager, UnitManager uManager, InputHandler iHandler, WarTug game){
		// Flush out the old screen components from GraphicsManager and InputHandler
		final GraphicsManager gMan = gManager;
		final UnitManager uMan = uManager;
		final InputHandler iHan = iHandler;
		final WarTug g = game;
		gManager.clearDrawableEntities();
		iHandler.clearButtonList();
		uManager.resetUnitLists();
		
		// Create the list of buttons that exist in the main menu screen
		ArrayList<Button> newButtons = new ArrayList<Button>();
		//Add the buttons here
		newButtons.add(new TextField(100, 50, 200, 50, "", TextureHolder.tex/*TextureHolder.joinMenuIPTextField*/)); // The IP Address TextField
		newButtons.add(new Button(100, 200, 50, 50, TextureHolder.tex/*TextureHolder.joinMenuJoinButton*/, 
				new ButtonAction() {
					public void onClick() {
						GameScreen.switchToMainMenu(gMan, uMan, iHan, g);
					}
					public void hover() {}})); // Join Game
		
		ArrayList<DrawableImage> newImages = new ArrayList<DrawableImage>();
		//Add the images here
		//newImages.add(new DrawableImage(0,0,25,600,400, TextureHolder.tex/*TextureHolder.joinMenuBackground*/));
		
		//Update the graphics manager, screen index, and input handler
		giveDrawablesToGraphicsHandler(newButtons, newImages, gManager);
		iHandler.setButtonList(newButtons);
		game.currentScreen = Screen.gameJoinMenu;
	}
	
	
	
	
	
	
	
	private static void giveDrawablesToGraphicsHandler(ArrayList<Button> buttons, ArrayList<DrawableImage> images, GraphicsManager gManager){
		// Add these buttons to GraphicsManager
		for (Button b: buttons){
			gManager.addDrawableEntity(b);
		}
		// Add these DrawableImages to GraphicsManager
		for (DrawableImage i: images){
			gManager.addDrawableEntity(i);
		}
	}
	
	
	
}
